//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELAAUDIO_H__
#define __ELAAUDIO_H__

//
// A 32 bits integer represents the state of a audiocard
//  Bit31: Power
//  Bit30-Bit24: Call State
//  Bit23-Bit20: Right channel source of audio in
//  Bit19-Bit16: Left channel source of audio in
//  Bit15-Bit8: Audio out device
//  Bit7-Bit0: Basic State
//
// 1. Basic state. Bit0-Bit7
//    When audiocard is used, must have at least one of them.
//    All are mutually exclusive expect STATE_AUDIOIN and CALL_HANDFREE
#define STATE_AUDIOOUT          0x00000001
#define STATE_AUDIOIN           0x00000002
#define STATE_CALL              0x00000004
#define STATE_FM                0x00000008
// 2. Audio out device. Bit8-Bit15
#define AUDIOOUT_SPEAKER        0x00000100
#define AUDIOOUT_HEADSET        0x00000200
#define AUDIOOUT_BLUETOOTH      0x00000400
// 3. Audio in device
// Bit16-Bit19:  Left channel
// Bit20-Bit23:  Right channel
#define AUDIOIN_MAINMIC      0  // MIC on phone
#define AUDIOIN_HEADSET      1  // MIC on normal headset
#define AUDIOIN_BLUETOOTH    2  // MIC on wireless headset(such as bluetooth)
#define AUDIOIN_LINE1        3  // Line 1 input (Normal mode Rx voice signal)
#define AUDIOIN_LINE2        4  // Line 2 input (Headset mode Rx voice signal)
#define AUDIOIN_SOURCEMASK   0xf
#define AUDIOIN_SETLEFTSOURCE(source)  (((source) & 0xf) << 16)
#define AUDIOIN_SETRIGHTSOURCE(source) (((source) & 0xf) << 20)
#define AUDIOIN_GETLEFTSOURCE(state)  (UINT)(((state) & 0x000f0000) >> 16)
#define AUDIOIN_GETRIGHTSOURCE(state) (UINT)(((state) & 0x00f00000) >> 20)
// 4. Call State. Bit24-Bit30
#define CALL_NORMAL             0
#define CALL_HANDFREE           1
#define CALL_HEADSET            2
#define CALL_BLUETOOTH          3
#define CALL_MODEMASK           0x7f
#define CALL_SETMODE(call)   (((call) & 0xf) << 24)
#define CALL_GETMODE(state)  (UINT)(((state) & 0x7f000000) >> 24)
// 5. Power state. Bit31
#define POWER_CLOSE             0x80000000 // Only for playing and recording

typedef struct
{
    int   SampleRate;
    short BitsPerSample; // 8 or 16
    short Channels; // 1 or 2
} Audio_Params;

typedef struct
{
    int State; // Audio driver state
    Audio_Params AudioOutParams; // Audio out params
    Audio_Params AudioInParams; // Audio in params
} Audio_Status;

#endif//__ELAAUDIO_H__
